#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	while(cin>>s && s != "0")
	{
		int sum = 0, sum2 = 0;
		for(auto i:s)
			sum += i-'0';
		while(sum > 9)
		{
			swap(sum, sum2);
			while(sum2)
			{
				sum += sum2%10;
				sum2 /= 10;
			}
		}
		cout<<sum<<endl;
	}
	return 0;
}
